//
//  IndexViewController.m
//  OutesIOS
//
//  Created by norman on 2019/1/4.
//  Copyright © 2019 norman. All rights reserved.
//

#import "IndexViewController.h"
#import "UITapLabel.h"
#import "Project_TabViewController.h"
#import "Project_Step1ViewController.h"
#import "ProjectContentViewController.h"
#import "ProductContentViewController.h"
#import "SystemContentViewController.h"
#import "AppDelegate.h"
#import "UITapView.h"

@interface IndexViewController ()

@end

@implementation IndexViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViews];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    [UIApplication sharedApplication].statusBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
     [UIApplication sharedApplication].statusBarHidden = NO;
}

- (void)setupViews {
    self.view.backgroundColor = [UIColor colorFromHexString:@"#ec7e3e"];
    
    UILabel *title = [UILabel labelSingleLineboldFontSize:18 content:@"中广欧特斯5C助理"];
    title.textColor = [UIColor whiteColor];
    title.centerX = kScreen_Width/2;
    
    title.y = 20;
    if (iPhone_X) {
        title.y += 40;
    }
    [self.view addSubview:title];
    UIImage *img = [UIImage imageNamed:@"index_bg"];
    UIImageView *bg = [[UIImageView alloc]initWithImage:img];
    bg.frame = CGRectMake(30, CGRectGetMaxY(title.frame) + 60, kScreen_Width - 60, 0);
    bg.height = img.size.height*(kScreen_Width - 60)/img.size.width;
//    bg.contentMode = UIViewContentModeScaleAspectFill;
    [self.view addSubview:bg];
    
    UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 0)];
    navView.backgroundColor = [UIColor whiteColor];
    UITapView *nav1 = [self setupNavigateView:0 andTitle:@"5C选型报价" andDesc:@"快速完成5C系统的选型报价" andImg:@"tab_project_normal"];
    nav1.x = 0;
    nav1.y = 20;
    [navView addSubview:nav1];
    UITapView *nav2 = [self setupNavigateView:1 andTitle:@"集中采暖选型" andDesc:@"快速完成集中采暖选型及运行费用评估" andImg:@"tab_resource_normal"];
    nav2.x = 0;
    nav2.y = CGRectGetMaxY(nav1.frame);
    [navView addSubview:nav2];
    UITapView *nav3 = [self setupNavigateView:2 andTitle:@"产品信息" andDesc:@"5C系统相关产品信息" andImg:@"tab_product_normal"];
    nav3.x = 0;
    nav3.y = CGRectGetMaxY(nav2.frame);
    [navView addSubview:nav3];
    UITapView *nav4 = [self setupNavigateView:3 andTitle:@"系统设置" andDesc:@"系统相关信息设置" andImg:@"tab_mine_normal"];
    nav4.x = 0;
    nav4.y = CGRectGetMaxY(nav3.frame);
    [navView addSubview:nav4];
    navView.height = CGRectGetMaxY(nav4.frame) + 30;
    if (iPhone_X) {
        navView.height += 34;
    }
    navView.y = kScreen_Height - navView.height;
    [self.view addSubview:navView];
    
}

- (UITapView*)setupNavigateView:(NSInteger)index andTitle:(NSString*)title andDesc:(NSString*)desc andImg:(NSString*)img {
    UITapView *view = [[UITapView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 70)];
    view.backgroundColor = [UIColor whiteColor];
    
    UIImageView *left = [[UIImageView alloc]initWithImage:[UIImage imageNamed:img]];
    left.x = 30;
    left.centerY = view.height/2;
    [view addSubview:left];
    
    UILabel *lbTitle = [UILabel labelSingleLineFontSize:15 content:title];
    lbTitle.textColor = BSBlackTextColor;
    lbTitle.x = CGRectGetMaxX(left.frame) + 7;
    lbTitle.y = view.height/2 - 3 - lbTitle.height;
    [view addSubview:lbTitle];
    
    UILabel *lbDesc = [UILabel labelSingleLineFontSize:13 content:desc];
    lbDesc.textColor = BSBlackTextColor1;
    lbDesc.x = CGRectGetMaxX(left.frame) + 7;
    lbDesc.y = view.height/2 + 3;
    [view addSubview:lbDesc];
    
    UIImageView *nav = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pushNextArrow"]];
    nav.x = kScreen_Width - 30 - nav.width;
    nav.centerY = view.height/2;
    [view addSubview:nav];
    
    [view addTargetsBlock:^(id obj) {
        [(AppDelegate *)[[UIApplication sharedApplication] delegate] showMainViewController:index];
    }];
    return view;
}


- (void)setupNavView {
    CGFloat padding = 50;
    CGFloat size = kScreen_Width/2 - padding;
    CGFloat y = kScreen_Height - 2*size - 50;
    if (iPhone_X) {
        y -= 34;
    }
    UIButton *project = [UIButton buttonWithType:UIButtonTypeCustom];
    [project setImage:[UIImage imageNamed:@"project_nav"] forState:UIControlStateNormal];
    [project setImage:[UIImage imageNamed:@"project_nav_1"] forState:UIControlStateHighlighted];
    [project addTarget:self action:@selector(navigateTo:) forControlEvents:UIControlEventTouchUpInside];
    //    project.backgroundColor = [UIColor grayColor];
    project.frame = CGRectMake(50, y, size, size);
    project.tag = 0;
    [self.view addSubview:project];
    
    UIButton *selection = [UIButton buttonWithType:UIButtonTypeCustom];
    [selection setImage:[UIImage imageNamed:@"selection_nav"] forState:UIControlStateNormal];
    [selection setImage:[UIImage imageNamed:@"selection_nav_1"] forState:UIControlStateHighlighted];
    [selection addTarget:self action:@selector(navigateTo:) forControlEvents:UIControlEventTouchUpInside];
    //    selection.backgroundColor = [UIColor grayColor];
    selection.frame = CGRectMake(size + 50, y, size, size);
    selection.tag = 1;
    [self.view addSubview:selection];
    
    UIButton *product = [UIButton buttonWithType:UIButtonTypeCustom];
    [product setImage:[UIImage imageNamed:@"product_nav"] forState:UIControlStateNormal];
    [product setImage:[UIImage imageNamed:@"product_nav_1"] forState:UIControlStateHighlighted];
    [product addTarget:self action:@selector(navigateTo:) forControlEvents:UIControlEventTouchUpInside];
    //    product.backgroundColor = [UIColor grayColor];
    product.frame = CGRectMake(50, y + size, size, size);
    product.tag = 2;
    [self.view addSubview:product];
    
    UIButton *system = [UIButton buttonWithType:UIButtonTypeCustom];
    [system setImage:[UIImage imageNamed:@"system_nav"] forState:UIControlStateNormal];
    [system setImage:[UIImage imageNamed:@"system_nav_1"] forState:UIControlStateHighlighted];
    [system addTarget:self action:@selector(navigateTo:) forControlEvents:UIControlEventTouchUpInside];
    //    system.backgroundColor = [UIColor grayColor];
    system.frame = CGRectMake(50 + size, y + size, size, size);
    system.tag = 3;
    [self.view addSubview:system];
}

- (void)navigateTo:(UIButton*)button {
    if (button.tag == 0) {
        [(AppDelegate *)[[UIApplication sharedApplication] delegate] showMainViewController:0];
//        ProjectContentViewController *vc = [ProjectContentViewController new];
//        [self.navigationController pushViewController:vc animated:YES];
    } else if (button.tag == 1) {
        [(AppDelegate *)[[UIApplication sharedApplication] delegate] showMainViewController:1];
//        [MBProgressHUD showSuccess:@"功能开发中，敬请期待。。。"];
    } else if (button.tag == 2) {
        [(AppDelegate *)[[UIApplication sharedApplication] delegate] showMainViewController:2];
//        [MBProgressHUD showSuccess:@"功能开发中，敬请期待。。。"];
//        ProductContentViewController *vc = [ProductContentViewController new];
//        [self.navigationController pushViewController:vc animated:YES];
    }else if (button.tag == 3) {
        [(AppDelegate *)[[UIApplication sharedApplication] delegate] showMainViewController:3];
        SystemContentViewController *vc = [SystemContentViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
